package com.gy.controller;

import com.gy.pojo.Notice;
import com.gy.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
public class NoticeController {
    @Autowired
    BaoXiuService baoXiuService;
    @Autowired
    LeiXingService leiXingService;
    @Autowired
    NoticeService noticeService;
    @Autowired
    UserService userService;
    @Autowired
    QuYuService quYuService;

    //查看公告
    @RequestMapping("/all/selectnotice")
    public String selectnotice(Model model){
        List<Notice> notices = noticeService.selectNT();
        model.addAttribute("notices",notices);

        return "notice/selectnotice";

    }

    //根据id查看公告
    @RequestMapping("/all/selectnoticebyid/{Nid}")
    public String selectByid(@PathVariable("Nid") int Nid,Model model){
        Notice notice = noticeService.selectNTByid(Nid);
        model.addAttribute("notice",notice);


        return "notice/selectnoticebyid";
    }

    //管理员管理公告
        //先来到查看公告页面
    @RequestMapping("/admin/selectnotice")
    public String ADMsele(Model model){
        List<Notice> notices = noticeService.selectNT();
        model.addAttribute("notices",notices);
        return "notice/ADMselectnotice";
    }
      //根据id查看公告
      @RequestMapping("/admin/selectnoticebyid/{Nid}")
      public String admselectByid(@PathVariable("Nid") int Nid,Model model){
          Notice notice = noticeService.selectNTByid(Nid);
          model.addAttribute("notice",notice);


          return "notice/ADMselectnoticebyid";
      }

      //根据ID删除公告
    @RequestMapping("/admin/deletenoticebyid/{Nid}")
      public String admdeletebyid(@PathVariable("Nid")int Nid){
            noticeService.deleteNTByID(Nid);

            return "redirect:/admin/selectnotice";
      }

      //增加公告
    //来到增加页面
    @RequestMapping("/admin/addnotice")
    public String admaddnt(){
        return "notice/addnotice";
    }
    //增加
    @PostMapping("/admin/addnotice")
    public String ADMaddnt(String Ntite,String Ntext,String Nname){
        noticeService.addNT(Nname,Ntite,Ntext);

        return "redirect:/admin/selectnotice";
    }





}
